﻿using Autodesk.AutoCAD.EditorInput;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.Runtime;

namespace AutoCADPlugin
{
    class 解一元二次方程的解
    {

        [CommandMethod("JFC")]
        public static void JFC()
        {
            double a; //交互获取
            double b; //交互获取
            double c; //交互获取

            double d;
            double e;
            double f;
            double g;
            double h;
            double i;
            double j;
            double k;

            //Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            Console.WriteLine("解一元二次方程ax*x+bx+c=0");
        aa: Console.WriteLine("请输入a的值：");
            a = double.Parse(Console.ReadLine());
            //a的值不能为0
            if (a==0)
            {
                Console.WriteLine("请注意a的值不能为0，请重新输入！");
                goto aa;
            }
            Console.WriteLine("请输入b的值：");
            b = double.Parse(Console.ReadLine());
            Console.WriteLine("请输入c的值：");
            c = double.Parse(Console.ReadLine());
            d = b * b;
            e = 4 * a * c;
            f = d-e ;
            g = (int)(Math.Sqrt(f));
            i = -b + g;
            j = -b - g;
            h = i / (2 * a);
            k = j / (2 * a);

            if (f == 0)
            {
                Console.WriteLine("此方程有一根为" + h);
            }
            else if(f>0)
            {
                Console.WriteLine("此方程有两跟为" + h);
                Console.WriteLine("              " + k);

            }
            else
            {
                Console.WriteLine("此方程没有根");

            }

        }
    }
}
